/**
 * 音频播放器插件
 * .audio-player标签必需加2个属性：data-src和title,其中,title内容为文件名,如果文件名为空则不渲染.
 * @param {jQuery} $
 * @returns {void}
 * @since 1.0 2014-7-22 by sutroon
 * @example
 *        <td><span class="audio-player" data-src="{:get_voc_url('sounds')}{$vo.dirName}/{$vo.music}" title="{$vo.music}"><a href="?s=VoiceMenu/item_edit/id/{$vo.id}.html">[编辑]</a><a href="#" onclick="JQUIHelper.confirm_redirect('?s=VoiceMenu/item_delete/id/{$vo.id}.html')">[删除]</a></span></td>
 */
(function ($) {
    $.fn.audioPlayer = function (options) {
        var opts = $.extend({}, $.fn.audioPlayer.defaults, options);
        return this.each(function () {
            var $this = $(this);
            var title = $this.attr('title');
            if (title) {
                var src = $this.data('src');
                var links = $this.html();
                var linkscount = $this.find('a').length;
                var str = '<div class="soplayer' + (linkscount > 0 ? ' lnkx' + linkscount : '') + '"><span class="playermask"><audio src="' + src + '" controls="controls">您的浏览器不支持播放器插件,请升级到IE10以上的浏览器版本或火狐、谷歌等现代浏览器</audio></span>' + links + '<i style="clearfix"></i></div>';
                $this.parent().addClass('tdplayer').attr('title', title).html(str);
            } else {
                if (opts.allowEmpty) {
                    $this.parent().html('');
                }
            }
        });
    };
    $.fn.audioPlayer.defaults = {allowEmpty: true};
})(jQuery);